package com.ryhx.wifi.base.model.newsinfo.dao.impl;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Component;

import com.ryhx.wifi.facade.base.entity.NewsInfo;
import com.ryhx.wifi.base.model.newsinfo.dao.NewsInfoDao;
import com.ryhx.wifi.common.exceptions.BizException;

import com.ryhx.osp.common.page.MysqlPageBean;
import org.apache.ibatis.session.RowBounds;

@Component("newsInfoDao")
public class NewsInfoDaoImpl implements NewsInfoDao {

	@Resource(name = "sqlSessionTemplate")
	private SqlSessionTemplate sqlSessionTemplate;

	@Override
	public NewsInfo getNewsInfo(Map<String, Object> query) throws BizException {
		return sqlSessionTemplate.selectOne("NewsInfoMapper.getNewsInfo", query);
	}

	@Override
	public List<NewsInfo> getNewsInfoList(NewsInfo newsInfo, MysqlPageBean pageBean) throws BizException {
		if(null == pageBean) {
			pageBean = new MysqlPageBean(0, 100);
		}
		return sqlSessionTemplate.selectList("NewsInfoMapper.getNewsInfoList", newsInfo, new RowBounds(pageBean.getLimitIndex(), pageBean.getLimit()));
	}

	@Override
	public Integer getNewsInfoListCount(NewsInfo newsInfo) throws BizException {
		return sqlSessionTemplate.selectOne("NewsInfoMapper.getNewsInfoListCount", newsInfo);
	}

	@Override
	public List<NewsInfo> getNewsInfoListByParams(Map<String, Object> params) throws BizException {
		return sqlSessionTemplate.selectList("NewsInfoMapper.getNewsInfoListByParams", params);
	}

	@Override
	public Integer getNewsInfoListCountByParams(Map<String, Object> params) throws BizException {
		return sqlSessionTemplate.selectOne("NewsInfoMapper.getNewsInfoListCountByParams", params);
	}

	@Override
	public int batchInsertNewsInfo(List<NewsInfo> list) throws BizException {
		return sqlSessionTemplate.insert("NewsInfoMapper.batchInsertNewsInfo", list);
	}

	@Override
	public int batchUpdateNewsInfo(List<NewsInfo> list) throws BizException {
		return sqlSessionTemplate.update("NewsInfoMapper.batchUpdateNewsInfo", list);
	}

	@Override
	public Long insertNewsInfo(NewsInfo newsInfo) throws BizException {
		sqlSessionTemplate.insert("NewsInfoMapper.insertNewsInfo", newsInfo);
		return newsInfo.getEntityId();
	}

	@Override
	public int updateNewsInfo(NewsInfo newsInfo) throws BizException {
		return sqlSessionTemplate.update("NewsInfoMapper.updateNewsInfo", newsInfo);
	}

	@Override
	public int updateNewsInfoWithoutNull(NewsInfo newsInfo) throws BizException {
		return sqlSessionTemplate.update("NewsInfoMapper.updateNewsInfoWithoutNull", newsInfo);
	}

	@Override
	public int updateNewsInfoByWhereSql(Map<String, Object> newsInfo) throws BizException {
		return sqlSessionTemplate.update("NewsInfoMapper.updateNewsInfoByWhereSql", newsInfo);
	}

	@Override
	public int truncateNewsInfo() throws BizException {
		return sqlSessionTemplate.delete("NewsInfoMapper.truncateNewsInfo");
	}

	@Override
	public int deleteNewsInfo(Map<String, Object> query) throws BizException {
		return sqlSessionTemplate.delete("NewsInfoMapper.deleteNewsInfo", query);
	}

	@Override
	public int deleteNewsInfoList(Map<String, Object> query) throws BizException {
		return sqlSessionTemplate.delete("NewsInfoMapper.deleteNewsInfoList", query);
	}

	@Override
	public int deleteNewsInfoByWhereSql(Map<String, Object> query) throws BizException {
		return sqlSessionTemplate.delete("NewsInfoMapper.deleteNewsInfoByWhereSql", query);
	}

	@Override
	public int batchDeleteNewsInfo(List<Long> list) throws BizException {
		return sqlSessionTemplate.delete("NewsInfoMapper.batchDeleteNewsInfo", list);
	}

	@Override
	public int batchDeleteNewsInfoList(List<NewsInfo> list) throws BizException {
		return sqlSessionTemplate.delete("NewsInfoMapper.batchDeleteNewsInfoList", list);
	}
}
